#ifndef dq_Record_h
#define dq_Record_h

#include "TransientState.h"
#include <db/Any.h>
#include <utility/String.h>

namespace serika
{
	namespace dq
	{
		template <class Type>
		class Record
		{
		public:
			Record(Type* type, TransientState::Enum state);
			virtual ~Record();

			void Save();
			void Delete();

			void MarkDelete() { this->ToDeleteState(); }

			const ut::String& GetString(const std::string& col, const ut::String& def = _T("")) const;
			int GetInt(const std::string& col, int def = 0) const;

			void Set(const std::string& col, const db::Any& any);

		protected:
			bool IsClean() const { return TransientState::Clean == mState; }
			bool IsDirty() const { return TransientState::Dirty == mState; }
			bool IsNew() const { return TransientState::New == mState; }
			bool IsDelete() const { return TransientState::Delete == mState; }

			void ToCleanState();
			void ToDeleteState();
			void ToDirtyState();

		private:
			TransientState::Enum mState;
			Type* mDb;
		};
	}
}

#include "Record.inl"

#endif
